package com.cictec.middleware.gps.engine.thread;
import java.util.Date;

import com.cictec.middleware.gps.engine.TimeEventBus;
import com.cictec.middleware.gps.engine.TimingObject;
import com.cictec.middleware.gps.engine.TimingPoint;
import com.cictec.middleware.gps.engine.TimingPointEvent;
import com.cictec.middleware.ribbon.loadbalancer.rule.ThreadContextHolder;

public class PointExecutorRunable implements Runnable {

	private TimeEventBus timeEventBus;
	private TimingObject timingObject;

	public PointExecutorRunable(TimingObject timingObject, TimeEventBus timeEventBus) {
		this.timingObject = timingObject;
		this.timeEventBus = timeEventBus;
	}

	@Override
	public void run() {
		try {
			if(timingObject instanceof TimingPoint){
				TimingPoint timingPoint = (TimingPoint) timingObject;
				ThreadContextHolder.setValue(timingPoint.getDevCode(), timingPoint.getCityCode());
				
				TimingPointEvent event = new TimingPointEvent(new Date(), timingPoint);
				timeEventBus.post(event);
			}
			
		} catch (Exception e) {
//			e.printStackTrace();
		}
		
	}
}
